package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.api.OptionApi;
import com.tanhua.dubbo.mappers.OptionMapper;
import com.tanhua.model.domain.Answer;
import com.tanhua.model.domain.Option;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

@DubboService
public class OptionApiImpl implements OptionApi {
    @Autowired
    private OptionMapper optionMapper;
    //保存选项
    @Override
    public void save(Option option) {
        optionMapper.insert(option);
    }

    /**
     * 根据题目id和选项id统计分数//适用于题目和选项之间是多多的关系时
     * @param answers
     * @return
     */
    @Override
    public Integer sum(List<Answer> answers) {
        // TODO: 2022/1/9 我的question和option是一对多的关系 所以直接用一个列找
        Integer score=optionMapper.findSumByAnswers(answers);
        //List<String> collect = answers.stream().map(answer -> answer.getOptionId()).collect(Collectors.toList());
        return score;
    }
}
